# -*- coding: utf-8 -*-
"""
@Time ： 2022/7/19 20:44
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：json字符串处理
"""
import json

# 什么是json字符串：字典数据结构的字符串体现
ddd = {'a':'b','c':1}
# 字典转为json字符串
ddd_str = json.dumps(ddd)
print(type(ddd_str))


res = r"""
jQuery11020180205193966801_1658234633810({"Srcid":"5809","ResultCode":"0",
"status":"0","QueryID":"1754765152","Result":[{"DisplayData":{"strategy":
{"tempName":"ip","precharge":"0","ctplOrPhp":"1"},"resultData":{"tplData":
{"srcid":"5809","resourceid":"5809","OriginQuery":"1.1.1.1","origipquery":"1.1.1.1",
"query":"1.1.1.1","origip":"1.1.1.1","location":"\u6cdb\u64ad Cloudflare","userip":"",
"showlamp":"1","tplt":"ip","titlecont":"IP\u5730\u5740\u67e5\u8be2","realurl":
"http:\/\/www.ip138.com\/","showLikeShare":"1","shareImage":"1","data_source":"AE"},
"extData":{"tplt":"ip","resourceid":"5809","OriginQuery":"1.1.1.1"}}},
"ResultURL":"http:\/\/www.ip138.com\/","Weight":"2","Sort":"1","SrcID":
"5809","ClickNeed":"0","SubResult":[],"SubResNum":"0","ar_passthrough":[],
"RecoverCacheTime":"0"}],"data":[{"srcid":"5809","resourceid":"5809",
"OriginQuery":"1.1.1.1","origipquery":"1.1.1.1","query":"1.1.1.1",
"origip":"1.1.1.1","location":"\u6cdb\u64ad Cloudflare","userip":"",
"showlamp":"1","tplt":"ip","titlecont":"IP\u5730\u5740\u67e5\u8be2","realurl":
"http:\/\/www.ip138.com\/","showLikeShare":"1","shareImage":"1"}],"ResultNum":"1"})
"""

# 怎么得到标准json字符串？字符串截取
# 怎么得到字符串里面某一个字符的下标
# 从开头找第一个{的下标
l_index = res.find('{')
# 从末尾倒着找第一个}的下标
r_index = res.rfind('}')
res = res[l_index:r_index+1]

# 怎么去掉换行
res = res.replace('\n',' ')
print(res)
# 怎么转为字典？json字符串转字典
res_dict = json.loads(res)
print(res_dict)